<template>
    <div class="page-box-rowp-left">
        <Form :label-width="85">
            <Row :gutter="32" class="code-row-bg">
                <Col :md="12" :lg="8" :xl="8" :xxl="6" style="border:none;">
                    <Form-item :label="$t('module.tenantManage.tenantName')">
                        <Input
                            v-model="tenantInfo.tenantName"
                            disabled
                        />
                    </Form-item>
                </Col>
                <Col :md="12" :lg="8" :xl="8" :xxl="6" style="border:none;">
                    <Form-item :label="$t('module.tenantManage.tenantID')">
                        <Input
                            v-model="tenantInfo.tenantId"
                            disabled
                        />
                    </Form-item>
                </Col>
                <Col :md="12" :lg="8" :xl="8" :xxl="6" style="border:none;">
                    <Form-item :label="$t('module.tenantManage.secretKey')">
                        <Input
                            v-model="tenantInfo.signKey"
                            disabled
                        />
                    </Form-item>
                </Col> 
                <Col :md="12" :lg="8" :xl="8" :xxl="6" style="border:none;">
                    <Form-item :label="$t('module.tenantManage.encryptionType')">
                        <Input
                            v-model="tenantInfo.encryptionType"
                            disabled
                        />
                    </Form-item>
                </Col>
                <Col :md="12" :lg="8" :xl="8" :xxl="6" style="border:none;">
                    <Form-item :label="$t('module.tenantManage.salt')">
                        <Input
                            v-model="tenantInfo.salt"
                            disabled
                        />
                    </Form-item>
                </Col>
                <Col :md="12" :lg="8" :xl="8" :xxl="6" style="border:none;">
                    <Form-item :label="$t('module.tenantManage.updatTime')">
                        <Input
                            v-model="tenantInfo.updatTime"
                            disabled
                        />
                    </Form-item>
                </Col> 
                <Col :md="12" :lg="8" :xl="8" :xxl="6" style="border:none;">
                    <Form-item :label="$t('module.tenantManage.remark')">
                        <Input
                            v-model="tenantInfo.remark"
                            disabled
                        />
                    </Form-item>
                </Col>
            </Row>
        </Form>
        <SelfAdaption>
          <Form
            :model="searchForm"
            ref="configForm"
            slot="adaption-bar"
            label-position="top"
            class="ivu-form-no-margin-bottom"
            inline
          >
            <Form-item prop="name" :label="$t('module.tenantManage.name')">
                <Input
                    type="text"
                    :maxlength="30"
                    v-model.trim="searchForm.name"
                    placeholder
                    
                    @on-enter="search"
                ></Input>
                </Form-item>
            <Form-item prop="button" class="search-solt-btn">
              <RPButton optType="search" @click="search" />
              <RPButton optType="reset" @click="reset" />
            </Form-item>
          </Form>
        </SelfAdaption>
        <InnerPageTable ref="tenantConfigTable" :config="tableConfig">
            <div slot="table-bar">
                <RPButton
                    optType="create"
                    @click="addTenant"
                    />
            </div>
        </InnerPageTable>
    </div>
</template>

<script>
import configEdit from './configEdit.vue'
import { getTenantConfigList, deleteConfig } from '@api/flowable/tenantManage.js'
import { tenantConfigColumns } from './columns.js'
// import IframeContainer from '@/components/IframeContainer.vue'
export default {
    name: 'tenant-config',
    // components: { IframeContainer },
    props:{
        tenantInfo:{
            type:Object,
            default(){
                return {}
            }
        }
    },
    data() {
        return {
            searchForm: {
                name: ''
            },
            tableConfig: {
                loadDataFn: ({ responseProcess, param }) => {
                    getTenantConfigList({...param,tenantId:this.tenantInfo.tenantId}).then(({ data }) => {
                        data.currentPage = data.pageNum
                        delete data.pageNum
                        data.recordCount = data.total
                        delete data.total

                        data.recordList = data.records
                        delete data.records
                        responseProcess(data)
                    })
                },
                columnsFn: tenantConfigColumns.bind(this),
                autoFirst: true,
                loading: false,
                initParam: { state: 1 }
            }
        }
    },
    methods: {
        search() {
            //刷新列表
            this.$refs['tenantConfigTable'].load(this.searchForm)
        },
        reset() {
            this.$refs['configForm'].resetFields()
            this.search()
        },
        addTenant() {
            let configInfo = {},
                tenantInfo = this.tenantInfo
            new this.$pageModal(
                configEdit,
                {
                    props: {
                        configInfo,
                        tenantInfo,
                    }
                },
                data => {
                    if(data) {
                        this.search()
                    }
                }
            )
        },
        editTenant(row) {
          let configInfo = row,
              tenantInfo = this.tenantInfo
          new this.$pageModal(
              configEdit,
              {
                  props: {
                    configInfo,
                    tenantInfo,
                  }
              },
              data => {
                  if(data) {
                      this.search()
                  }
              }
          )
        },
        _deleteTenant(row) {
            new $confirm(this.$t('common.warning.confirmToDelete'), this).then(() => {
                deleteConfig({id: row.id}).then(res => {
                    this.$Message.success({
                        content: this.$t('common.deleteSuccess'),
                        duration: 3
                    })
                    this.search()
                })
            })
        }
    }
}
</script>

<style lang="less" scoped>
.page-box-rowp-left{
  padding-top: 10px;
}
</style>